//
//  SegmentDemo.m
//  Exercise
//
//  Created by zhouxiaobo on 15/11/12.
//  Copyright © 2015年 mapath. All rights reserved.
//

#import "SegmentDemo.h"

@implementation SegmentDemo

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSArray *array = @[@"音乐",@"视频",@"图书",@"体育"];
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
    segment.frame = CGRectMake(screenWidth/2-80, 150, 160, 30);
    
    //设置选中2
    segment.selectedSegmentIndex = 2;
    
    [segment addTarget:self action:@selector(selectItem:) forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:segment];
    
    NSArray *imageArr = @[[UIImage imageNamed:@"icon_1"],[UIImage imageNamed:@"icon_2"],[UIImage imageNamed:@"icon_3"]];
    UISegmentedControl *segment1 = [[UISegmentedControl alloc]initWithItems:imageArr];
    segment1.frame = CGRectMake(screenWidth/2-225, 250, 450, 150);
    
    [self.view addSubview:segment1];
}

- (void)selectItem:(UISegmentedControl *)segment{
    NSLog(@"你选择了%d",segment.selectedSegmentIndex);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
